<template>
  <div>
    <van-cell>
      <span class="oa-title">学生OA管理系统</span>
    </van-cell>
    <van-cell-group class="login-form">
      <van-field left-icon="contact" label="用户名" v-model="form.account" placeholder="请输入用户名"></van-field>
      <van-field left-icon="contact" label="密  码" v-model="form.password" placeholder="请输入密码"></van-field>
      <van-button class="login-btn" @click="login" plain size="small" type="primary">登录</van-button>
    </van-cell-group>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        account: "alan",
        password: "alan"
      }
    };
  },
  methods: {
    login: function() {
      let _that=this;
      this.$ajax({
        method: "post",
        url: "/auth",
        data: this.form
      })
        .then(res=>{
            if(res.data.token){
                localStorage.setItem('token',res.data.token);
                _that.$router.push({path:'/students'})
            }
        })
        .catch(function(error) {
          console.log(error);
        });
    }
  }
};
</script>